/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MasterclassToevoegen.java
 *
 * Created on 20-dec-2011, 16:50:21
 */
package view;


import javax.swing.JOptionPane;
import model.Speler;
import model.Masterclass;
/**
 *
 * @author tomkeim
 */
public class MasterclassAanmaken extends javax.swing.JFrame {
    protected Speler[] spelers;
    /** Creates new form MasterclassToevoegen */
    public MasterclassAanmaken() {
        initComponents();
        
        spelers = Speler.getSpelers();
        
        for(int i=0;i<spelers.length;i++) {
            leraarCombobox.addItem(spelers[i]);
        }
        
       
        //Urenbox invullen
        for(int i=0;i<24;i++) {
            if(i<10) {
                uurTijdBox.addItem("0"+i);
            } else {
                uurTijdBox.addItem(""+i);
            }
        }
        
        //Minutenbox invullen
        for(int i=0;i<60;i++) {
            if(i<10) {
                minuutTijdBox.addItem("0"+i);
            } else {
                minuutTijdBox.addItem(""+i);
            }
        }
        
        //Dagenbox
        for(int i=1;i<=31;i++) {
            if(i<10) {
                dayField.addItem("0"+i);
            } else {
                dayField.addItem(""+i);
            }
        }
        
        //Maandenbox
        for(int i=1;i<=12;i++) {
            if(i<10) {
                monthField.addItem("0"+i);
            } else {
                monthField.addItem(""+i);
            }
        }
        
        //jarenbox
        for(int i=2000;i<=2030;i++) {
            if(i<10) {
                yearField.addItem("0"+i);
            } else {
                yearField.addItem(""+i);
            }
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        leraarCombobox = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        uurTijdBox = new javax.swing.JComboBox();
        minuutTijdBox = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        kostenField = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        minRatingField = new javax.swing.JTextField();
        toevoegenButton = new javax.swing.JButton();
        dayField = new javax.swing.JComboBox();
        monthField = new javax.swing.JComboBox();
        yearField = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Masterclass aanmaken");

        jLabel1.setText("Leraar kiezen:");

        leraarCombobox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                leraarComboboxActionPerformed(evt);
            }
        });

        jLabel2.setText("Datum(dd-mm-yyyy):");

        jLabel3.setText("Tijd: ");

        jLabel4.setText(":");

        jLabel5.setText("Kosten:");
        jLabel5.setToolTipText("Dit veld moet u als een getal invullen.");

        jLabel6.setText("Minimale rating:");
        jLabel6.setToolTipText("Dit veld moet u als heel getal invullen.");

        toevoegenButton.setText("Masterclass toevoegen");
        toevoegenButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                toevoegenButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(toevoegenButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel1)
                            .add(jLabel2)
                            .add(jLabel3)
                            .add(jLabel5)
                            .add(jLabel6))
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(16, 16, 16)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(leraarCombobox, 0, 241, Short.MAX_VALUE)
                                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                        .add(uurTijdBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(jLabel4)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(minuutTijdBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                    .add(kostenField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 241, Short.MAX_VALUE)
                                    .add(minRatingField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 241, Short.MAX_VALUE)))
                            .add(layout.createSequentialGroup()
                                .add(18, 18, 18)
                                .add(dayField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(monthField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(yearField, 0, 171, Short.MAX_VALUE)))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap(32, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(leraarCombobox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(dayField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(monthField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(yearField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(minuutTijdBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(uurTijdBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel4))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel5)
                    .add(kostenField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel6)
                    .add(minRatingField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(toevoegenButton))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void leraarComboboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_leraarComboboxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_leraarComboboxActionPerformed

    private void toevoegenButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_toevoegenButtonActionPerformed
       Speler leraar = (Speler) leraarCombobox.getSelectedItem();
       
       Masterclass masterclass = new Masterclass();
       masterclass.setLeraar(leraar);
       

       
       String datum_tijd = (String) yearField.getSelectedItem() + "-" +
                           (String) monthField.getSelectedItem() + "-"+
                           (String) dayField.getSelectedItem() + " " +
                           (String) uurTijdBox.getSelectedItem() + ":" +
                           (String) minuutTijdBox.getSelectedItem()+":00";
        
       
       masterclass.setDatumTijd(datum_tijd);
       
       try {
            masterclass.setKosten(Double.parseDouble(kostenField.getText()));
            masterclass.setMinimaleRating(Integer.parseInt(minRatingField.getText()));
            
            if(masterclass.insert() == true) {
                JOptionPane.showMessageDialog(null, "De masterclass is met success toegevoegd","Actie voltooid",JOptionPane.INFORMATION_MESSAGE);
                this.dispose();
            } else {
                JOptionPane.showMessageDialog(null, "Er is wat mislukt tijdens het toevoegen van de Masterclass. Probeer het opnieuw.","Actie mislukt",JOptionPane.ERROR_MESSAGE);
            }
       } catch(NumberFormatException e) {
            JOptionPane.showMessageDialog(null, "Voer alle velden correct in.","Actie mislukt",JOptionPane.ERROR_MESSAGE);
       }
       
       
    }//GEN-LAST:event_toevoegenButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MasterclassAanmaken.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MasterclassAanmaken.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MasterclassAanmaken.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MasterclassAanmaken.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MasterclassAanmaken().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox dayField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JTextField kostenField;
    private javax.swing.JComboBox leraarCombobox;
    private javax.swing.JTextField minRatingField;
    private javax.swing.JComboBox minuutTijdBox;
    private javax.swing.JComboBox monthField;
    private javax.swing.JButton toevoegenButton;
    private javax.swing.JComboBox uurTijdBox;
    private javax.swing.JComboBox yearField;
    // End of variables declaration//GEN-END:variables
}
